package icu.bughub.app.app

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.view.WindowCompat
import com.tencent.rtmp.TXLiveBase
import com.tencent.rtmp.TXLiveBaseListener
import icu.bughub.app.app.ui.components.NavHostApp
import icu.bughub.app.app.ui.theme.WAppTheme


class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //让内容显示在状态栏和系统导航栏后面 状态栏和导航栏会遮盖部分内容
        WindowCompat.setDecorFitsSystemWindows(window, false)

        /*window.decorView.systemUiVisibility =
            window.decorView.systemUiVisibility or android.view.View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN*/

        /*

                WindowInsetsControllerCompat(window, window.decorView).let { controller ->
                    //controller.hide(WindowInsetsCompat.Type.statusBars())
                    //controller.hide(WindowInsetsCompat.Type.navigationBars())
                    // Set behavior to show transient bars by swipe
                    controller.systemBarsBehavior =
                        WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE

                    // Set light status bar and navigation bar appearance
                    controller.isAppearanceLightStatusBars = true // 状态栏使用亮色样式
                    controller.isAppearanceLightNavigationBars = true // 导航栏使用亮色样式
                }

        */

        //获取状态栏高度
        var statusBarHeight = 0
        val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
        if (resourceId > 0) {
            statusBarHeight = resources.getDimensionPixelSize(resourceId)
        }

        WindowCompat.setDecorFitsSystemWindows(window, true)

        val licenseURL =
            "https://license.vod2.myqcloud.com/license/v2/1300501617_1/v_cube.license" // 获取到的 license url
        val licenseKey = "9b3ad1f14d7da220da7c54d642ca0f9d" // 获取到的 license key
        TXLiveBase.getInstance().setLicence(this, licenseURL, licenseKey)
        TXLiveBase.setListener(object : TXLiveBaseListener() {
            override fun onLicenceLoaded(result: Int, reason: String?) {
                Log.i("", "onLicenceLoaded: result:" + result + ", reason:" + reason)
            }
        })

        enableEdgeToEdge()
        setContent {
            WAppTheme {
                Scaffold(
                    modifier = Modifier.fillMaxSize(),
                    contentColor = MaterialTheme.colorScheme.background,
                    containerColor = MaterialTheme.colorScheme.background
                ) { innerPadding ->
                    /*Greeting(
                        name = "Android",
                        modifier = Modifier.padding(innerPadding)
                    )*/
                    //MainFrame()
                    NavHostApp()
                    //LoginScreen()
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    Text(
        text = "Hello $name!",
        modifier = modifier
    )
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    WAppTheme {
        Greeting("Android")
    }
}